/*
 * Copyright (C) 2009  Sylvain Maucourt (smaucourt@gmail.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 *
 */
package net.sylvek.where;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Window;
import android.widget.Toast;

public class DlgActivity extends Activity {

    protected final static int CHECK_YOUR_PERMISSION = 1;

    protected final static int ASK_DLG = 0;

    private boolean extendedOk = false;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }

    @Override
    protected void onStart()
    {
        super.onStart();
        showDialog(ASK_DLG);
    }

    protected synchronized boolean isExtendedPermission()
    {
        return extendedOk;
    }

    @Override
    protected Dialog onCreateDialog(int id)
    {
        switch (id) {
        case CHECK_YOUR_PERMISSION:
            return new AlertDialog.Builder(this).setTitle(R.string.publish_stream)
                    .setMessage(R.string.publish_stream_summary)
                    .setCancelable(false)
                    .setPositiveButton(android.R.string.ok, new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which)
                        {
                            startActivity(new Intent(DlgActivity.this, Settings.class));
                        }
                    })
                    .setNegativeButton(android.R.string.cancel, new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which)
                        {
                            finish();
                        }
                    })
                    .create();
        default:
            return null;
        }
    }

    protected Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg)
        {
            String e = msg.obj.toString();
            Toast.makeText(DlgActivity.this, e, Toast.LENGTH_LONG).show();
        }
    };
}
